import torchvision
from torch.utils.tensorboard import SummaryWriter

dataset_transform = torchvision.transforms.Compose([
    torchvision.transforms.Resize((64, 64)),  # 调整图像大小
    torchvision.transforms.ToTensor(),  # 将图像转换为Tensor
])

# download 常年设置为True就好，再次下载会自动跳过
# 但注意，此时并没有真正下载，因为内存不够了QAQ
train_set = torchvision.datasets.CIFAR10(root="week1/PyTorch学习/dataset_CIFAR10",train = True,transform=dataset_transform,download=True) #训练集
test_set = torchvision.datasets.CIFAR10(root="week1/PyTorch学习/dataset_CIFAR10",train = False,transform=dataset_transform,download=True) #测试集


""" print(test_set[0]) #输出第一个数据 #<PIL.Image.Image image mode=RGB size=32x32 at 0x7F8B6C0D3A60, 3>
print(test_set.classes) #输出所有的类别 #['airplane', 'automobile', 'bird', 'cat', 'deer', 'dog', 'frog', 'horse', 'ship', 'truck']

img,target = test_set[0] #获取第一个数据和标签
print(img) #<PIL.Image.Image image mode=RGB size=32x32 at 0x7F8B6C0D3A60>
print(target) #3
print(test_set.classes[target]) #cat
img.show() #显示图片 """

writer = SummaryWriter("week1/PyTorch学习/3-transformer/logs_CIFAR10")
for i in range(10):
    img,target = test_set[i]
    writer.add_image("test_Set",img, i)

writer.close()

# tensorboard --logdir=week1/PyTorch学习/3-transformer/logs_CIFAR10 --port=6007
